home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_2 / issue_01 / wimp / userdrag (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1995-06-22  |  7.4 KB  |  324 lines

  1.  >$.Wimp.UserDrag
  2.  *********************************
  3.  *        Dragging the WIMP      *
  4.  * written by Adrian Philip Look *
  5.  *        5th October 1988       *
  6.  *********************************
  7. sys_reporterror
  8. sys_variables
  9. sys_startup
  10. program_startup
  11. sys_reporterror
  12.  "Wimp_ForceRedraw",-1,0,0,1280,1024
  13. quit%=
  14.  "Wimp_Poll",mask%,block% 
  15.  reason%
  16. program_wimppoll(reason%)
  17.  quit%
  18. sys_reporterror
  19. wimp_closedown
  20. $;" at line ";
  21. sys_startup
  22. ("Close")
  23.  "OS_CLI","Print $.Wimp.WimpFont"
  24.  "OS_CLI","Print $.Wimp.Palette"
  25. version%=
  26. wimp_initialise
  27.  0,143:
  28. ("fx 25 0")
  29. sys_variables
  30.  block% &4000
  31.  icondata% 11
  32. bodgeit%=
  33. mask%=0
  34. sys_quit
  35. quit%=
  36. wimp_closedown
  37. sys_windowinfo(block%)
  38. x0%=block%!4
  39. y0%=block%!8
  40. x1%=block%!12
  41. y1%=block%!16
  42. scx%=block%!20
  43. scy%=block%!24
  44. pos%=block%!28
  45. =Kbx%=x0%-scx%:by%=y1%-scy% : 
  46.  all drawing should be relative to bx%,by%
  47. WINDOWS
  48. AM-------------------------------------------------------------------------
  49. sys_windowcolours(tfg%,tbg%,wfg%,wbg%,so%,sin%,hi%)
  50. windowtitlefg%=tfg%
  51. windowtitlebg%=tbg%
  52. windowworkfg%=wfg%
  53. windowworkbg%=wbg%
  54. scrollout%=so%
  55. scrollin%=sin%
  56. highlight%=hi%
  57. sys_windowextent(sx%,sy%,sizex%,sizey%)
  58. scrx%=sx%
  59. scry%=sy%
  60. wx0%=0
  61. wy0%=-sizey%
  62. wx1%=sizex%
  63. wy1%=0
  64. sys_windowflags(tb,mv,vts,hts,wmr,pan,oma,boq,sra,srd)
  65.  flags%
  66.  -tb 
  67.  flags%=flags% 
  68.  &01 : 
  69.  title bar
  70.  -mv 
  71.  flags%=flags% 
  72.  &02 : 
  73.  movable
  74.  -vts 
  75.  flags%=flags% 
  76.  &04 : 
  77.  vertical scroll bar
  78.  -hts 
  79.  flags%=flags% 
  80.  &08 : 
  81.  horzintal scroll bar
  82.  -wmr 
  83.  flags%=flags% 
  84.  &10 : 
  85.  can be redrawn by AWM
  86.  -pan 
  87.  flags%=flags% 
  88.  &20 : 
  89.  window is a pane
  90.  -oma 
  91.  flags%=flags% 
  92.  &40 : 
  93.  window can go outside main area
  94.  -boq 
  95.  flags%=flags% 
  96.  &80 : 
  97.  back and quit box
  98.  -sra 
  99.  flags%=flags% 
  100.  &100 : 
  101.  scroll-rqst returned (auto-repeat)
  102.  -srd 
  103.  flags%=flags% 
  104.  &200 : 
  105.  scroll-rqst returned (debounced)
  106. =flags%
  107. sys_createwindow(x0%,y0%,x1%,y1%,pos%,iconflags%,wflags%,bt%)
  108.  x,handle%
  109. block%+=4
  110. f+block%!0=x0% : 
  111.  window screen position
  112. block%!4=y0%
  113. block%!8=x1%
  114. block%!12=y1%
  115. j+block%!16=scrx% : 
  116.  scroll bar position
  117. block%!20=scry%
  118. l,block%!24=pos% : 
  119.  window stack position
  120. m&block%!28=wflags% : 
  121.  window flags
  122. n(block%?32=windowtitlefg% : 
  123.  colours
  124. block%?33=windowtitlebg%
  125. block%?34=windowworkfg%
  126. block%?35=windowworkbg%
  127. block%?36=scrollout%
  128. block%?37=scrollin%
  129. block%?38=highlight%
  130. block%?39=0 : 
  131.  reserved
  132. v+block%!40=wx0% : 
  133.  work area definition
  134. block%!44=wy0%
  135. block%!48=wx1%
  136. block%!52=wy1%
  137. z1block%!56=iconflags% : 
  138.  title bar icon flags
  139. {/block%!60=bt%<<12 : 
  140.  work area button type
  141. |0block%!64=0 : 
  142.  sprite control block pointer
  143. block%!68=0 : 
  144.  reserved
  145.  x=0 
  146.  11:!(block%+72+x)=icondata%!x:
  147.  x : 
  148.  title icon data
  149. !block%!84=0 : 
  150.  no of sprites
  151. &handle%=
  152. wimp_createwindow(block%)
  153. block%-=4:block%!0=handle%
  154. =handle%
  155. L------------------------------------------------------------------------
  156. wimp_initialise
  157.  version%,x%
  158.  "Wimp_Initialise" 
  159.  version%
  160. bodgeit%=(version%<18)
  161.  bodgeit% 
  162.  oldfx%(9)
  163.  x%=0 
  164.  "OS_Byte",x%+220,2,0 
  165.  ,oldfx%(x):
  166.  "OS_Bytes",219,2,0 
  167.  ,oldfx%(9)
  168. =version%
  169. wimp_createwindow(block%)
  170.  handle%
  171.  "Wimp_CreateWindow",,block% 
  172.  handle%
  173. =handle%
  174. wimp_deletewindow(handle%)
  175. !block%=handle%
  176.  "Wimp_DeleteWindow",,block%
  177. wimp_openwindow(block%)
  178.  "Wimp_OpenWindow",,block%
  179. wimp_closewindow(handle%)
  180. !block%=handle%
  181.  "Wimp_CloseWindow",,block%
  182. wimp_closedown
  183.  bodgeit% 
  184.  x%=0 
  185.  "OS_Byte",x%+220,oldfx%(x%),0 
  186.  "OS_Bytes",219,oldfx%(9),0
  187.  "Wimp_CloseDown"
  188. 0THE ACTUAL PROGRAM 
  189.  THE WIMP IMPLEMENTATION
  190. M-------------------------------------------------------------------------
  191. program_startup
  192.  circle(2,2)
  193.  i=0 
  194. 7circle(i,0)=
  195. (1079)+100 : 
  196.  x co-ordinate of circle
  197. 7circle(i,1)=-
  198. (823)-100 : 
  199.  y co-ordinate of circle
  200. 0circle(i,2)=
  201. (50)+50    : 
  202.  radius of circle
  203. present=-1
  204. drag=
  205. sys_windowcolours(14,13,7,0,4,13,11)
  206. sys_windowextent(0,0,1279,1023)
  207. 1wflags%=
  208. sys_windowflags(1,1,1,1,0,0,0,1,0,0)
  209. (iconflags%=&19:$icondata%="DRAGGING"
  210. Dwindow%=
  211. sys_createwindow(0,0,1279,1023,-1,iconflags%,wflags%,6)
  212. wimp_openwindow(block%)
  213. program_calclimits
  214. .cx0%=circle(present,0)-circle(present,2)-4
  215. .cy0%=circle(present,1)-circle(present,2)-4
  216. .cx1%=circle(present,0)+circle(present,2)+4
  217. .cy1%=circle(present,1)+circle(present,2)+4
  218. program_wimppoll(reason%)
  219.  reason% 
  220.  0 : 
  221.  drag>0 
  222. program_updatedrag
  223.  1 : 
  224. program_redrawwindow
  225.  2 : 
  226. wimp_openwindow(block%)
  227.  3 : 
  228. wimp_closewindow(!block%)
  229.  6 : 
  230. program_processbuttons
  231.  7 : drag=0:
  232. program_updatedrag : 
  233.  drag finished
  234. program_redrawwindow
  235.  "Wimp_RedrawWindow",,block% 
  236.  more
  237.  get the top left-hand corner of the window (bx%,by%) in OS units
  238. sys_windowinfo(block%)
  239.  more
  240.  plot backwards, so that circle 0 is on the top
  241.  i=2 
  242.  0,10+i : 
  243.  different colours
  244.  bx%+circle(i,0),by%+circle(i,1)
  245.  &9D,bx%+circle(i,0)+circle(i,2),by%+circle(i,1)
  246.  "Wimp_GetRectangle",,block% 
  247.  more
  248. program_updatedrag
  249.  x%,y%,b%
  250.  mx%=x% 
  251.  my%=y% 
  252.  drag 
  253.  5 : 
  254. program_calclimits
  255. >         
  256.  "Wimp_ForceRedraw",window%,cx0%,cy0%,cx1%,cy1%
  257. &         circle(present,0)+=x%-mx%
  258. &         circle(present,1)+=y%-my%
  259.          mx%=x%:my%=y%
  260.           
  261. program_calclimits
  262. >         
  263.  "Wimp_ForceRedraw",window%,cx0%,cy0%,cx1%,cy1%
  264.  7 : 
  265. program_calclimits
  266. >         
  267.  "Wimp_ForceRedraw",window%,cx0%,cy0%,cx1%,cy1%
  268. <         x=bx%+circle(present,0):y=by%+circle(present,1)
  269. #         d=
  270. ((x-x%)^2+(y-y%)^2)
  271.           circle(present,2)=d
  272.          mx%=x%:my%=y%
  273.           
  274. program_calclimits
  275. >         
  276.  "Wimp_ForceRedraw",window%,cx0%,cy0%,cx1%,cy1%
  277. program_processbuttons
  278.  (block%!8 
  279.  &10)>0 
  280.  drag=7 : 
  281.  drag with the adjust
  282.  (block%!8 
  283.  &40)>0 
  284.  drag=5 : 
  285.  drag with the select
  286. <mx%=block%!0:my%=block%!4 : 
  287.  get the mouse co-ordinates
  288. program_intersect 
  289.  drag=
  290.  drag>0 
  291. program_initdrag
  292. program_intersect
  293.  get the top left-hand corner of the window (bx%,by%) in OS units
  294. block%!0=window%
  295.  "Wimp_GetWindowState",,block%
  296. sys_windowinfo(block%)
  297.  check for intersection when mouse is at (mx%,my%)
  298. present=-1
  299.  i=0 
  300. 'x=bx%+circle(i,0):y=by%+circle(i,1)
  301. ((x-mx%)^2+(y-my%)^2)
  302.  d<=circle(i,2) 
  303.  present=i:i=99
  304. 1=(i=100) : 
  305.  i=100 if intersection occurs!!!!
  306. program_initdrag
  307. block%!0=window%
  308.  "Wimp_GetWindowState",,block%
  309. sys_windowinfo(block%)
  310. program_calclimits
  311.  drag type
  312. block%!4=drag
  313.  initial box (bounding the circle)
  314. block%!8=bx%+cx0%
  315. block%!12=by%+cy0%
  316. block%!16=bx%+cx1%
  317. block%!20=by%+cy1%
  318.  parent box (area in which the box may be moved)
  319. block%!24=x0%
  320. block%!28=y0%
  321. block%!32=x1%
  322. block%!36=y1%
  323.  "Wimp_DragBox",,block%
  324.